package com.HospitalOutpatient.controller;

import com.HospitalOutpatient.annotation.LoginToken;
import com.HospitalOutpatient.dto.DiagnosisDto;
import com.HospitalOutpatient.entity.Reception;
import com.HospitalOutpatient.service.DiagnosisService;
import com.HospitalOutpatient.vo.DiagnosisVo;
import com.HospitalOutpatient.vo.DoctorAndOutpatientAndUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/diagnosis")
public class DiagnosisController {

    @Autowired
    private DiagnosisService diagnosisService;
    @LoginToken
    @PostMapping("/addDiagnosis")
    public Result addDiagnosis(@RequestBody DiagnosisDto diagnosisDto){
        if(diagnosisService.addDiagnosis(diagnosisDto) == false){
            return new Result(Code.SAVE_ERR,null,"添加诊断结果失败");
        }

        return new Result(Code.SAVE_OK,null,"添加诊断结果成功");
    }
    @LoginToken
    @PostMapping("/getDiagnosisByReceptionId")
    public Result getDiagnosisByReceptionId(@RequestBody Reception reception){
        DiagnosisVo diagnosisVo = diagnosisService.getDiagnosisByReceptionId(reception.getReceptionId());

        if(diagnosisVo == null){
            return new Result(Code.GET_ERR,null,"获取诊断结果失败");
        }

        return new Result(Code.GET_OK,diagnosisVo,"获取诊断结果成功");
    }

}
